﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Forex
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            button1.Text = "OK";
            button2.Text = "Add";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.IO.StreamReader sr;
            try
            {
                sr = new System.IO.StreamReader(Application.StartupPath + "\\usd.txt",
                    System.Text.Encoding.GetEncoding(1251));
                DateTime dateStart = monthCalendar1.SelectionStart;
                DateTime dateEnd = monthCalendar1.SelectionEnd;

                string st1, st2 = "";
                DateTime date;
                listBox1.Items.Clear();

                //read file data
                while (!sr.EndOfStream)
                {
                    st1 = sr.ReadLine();
                    date = System.Convert.ToDateTime(st1);
                    st2 = sr.ReadLine();
                    if ((date >= dateStart) && (date <= dateEnd))
                    {
                        listBox1.Items.Add(st1 + " " + st2);
                    }
                }
                sr.Close();
                if (listBox1.Items.Count == 0)
                {
                    listBox1.Items.Add("----No Data----");
                }
            }
            catch (Exception exc) 
            {
                MessageBox.Show
                    (
                    "Err data file \n" +
                    exc.ToString(),
                    "Forex",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                button1.Enabled = false;
                    
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 frm = new Form2();
            frm.Show();
        }
    }
}
